﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TwoWheels.Account;
using System.Data;

namespace TwoWheels
{
    public partial class productsList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CategoriesView2.Columns[3].Visible = false;

            if (Session["UserShoppingCartInfo"] != null)
            {                    
                CategoriesView2.Columns[3].Visible = true;
            }
                                
            foreach(GridViewRow row in CategoriesView2.Rows)
            {
                if (int.Parse(row.Cells[2].Text) <= 0)
                {
                    row.Cells[3].Visible = false;
                }
            }
        }

        protected void addToCart_Button(object sender, EventArgs e)
        {
            UserShoppingCart cart = Session["UserShoppingCartInfo"] as UserShoppingCart;
            Button button = sender as Button;

            int rowNumber =int.Parse(button.CommandArgument);
            int id =(int) CategoriesView2.DataKeys[rowNumber].Values[0] ;

            cart.addToCart(id);

            Response.Redirect("~/Account/Cart.aspx");
        }

    
    }
}